#include "global.h"


bit flag_sequence_running;
bit flag_sequence_finished=0;
bank3 unsigned char job_selector = 0;
	

const struct SequenceType DCI_TOSHIBA_6HP[]={
//  { lenght of stage in secs , compfreq, eev, fan speed, RV,message }
	{5,   0,  150, 0,  2,  "Power connected     "},  // test started
	{55,  0,  150, 0,  2,  "Inrush Charging     "}, //  50s inrush 
	{30,  40, 150, 1,  2,  "Compressor Starting "}, // compressor start
	{45,  60, 150, 1,  2,  "Current Burst    45s"}, // 60 sec Acceleration 
	
	{300, 50, 150, 2,  2,  "Heating Mode    300s"}, // 5min 40s heat mode
	{70,  50, 150, 1,  2,  "Heating Test  60 sec"}, // 1min heat mode Judge
	
	{10,  0,  10,  1,  2,  "Stop Compressor 10s "}, // 10sec  - stop compressor 
	{100, 60, 10,  1,  1,  " EEV Test      100s "}, // 120sec  - switch to cool - EEV Gas pumping
	
	{200, 60, 200, 3,  1,  "Cooling Mode    200s"}, // 2min max freq Eev -med	
	{60,  60, 200, 3,  1,  "Cooling Test  60 sec"}, // 1min max freq eev-med  //strong judje
	
	{60,  60, 50,  3,  1,  "Perform Pump Down   "},  // perform pump down
	{10,  30, 50,  3,  1,  "Disconnect Power    "}, // stop condition  --  or end condition 
	{0,   0,   0,  0,  0,  "Test Ended			"}
	};

const struct SequenceType DCI_TOSHIBA_4HP[]={
//  { lenght of stage in secs , compfreq, eev, fan speed, RV,message }
	{5,   0,  150, 0,  2,  "Power connected     "},  // test started
	{55,  0,  150, 0,  2,  "Inrush Charging     "}, //  50s inrush 
	{30,  40, 150, 1,  2,  "Compressor Starting "}, // compressor start
	{45,  60, 150, 1,  2,  "Current Burst    45s"}, // 60 sec Acceleration 
	
	{300, 50, 150, 2,  2,  "Heating Mode    300s"}, // 5min 40s heat mode
	{70,  50, 150, 1,  2,  "Heating Test  60 sec"}, // 1min heat mode Judge
	
	{10,  0,  10,  1,  2,  "Stop Compressor 10s "}, // 10sec  - stop compressor 
	{100, 60, 10,  1,  1,  " EEV Test      100s "}, // 120sec  - switch to cool - EEV Gas pumping
	
	{200, 60, 200, 3,  1,  "Cooling Mode    200s"}, // 2min max freq Eev -med	
	{60,  60, 200, 3,  1,  "Cooling Test  60 sec"}, // 1min max freq eev-med  //strong judje
	
	{60,  60, 50,  3,  1,  "Perform Pump Down   "},  // perform pump down
	{10,  30, 50,  3,  1,  "Disconnect Power    "}, // stop condition  --  or end condition 
	{0,   0,   0,  0,  0,  "Test Ended			"}
	};

const struct SequenceType DCI_TOSHIBA_5HP[]={
//  { lenght of stage in secs , compfreq, eev, fan speed, RV,message }
	{5,   0,  150, 0,  2,  "Power connected     "},  // test started
	{55,  0,  150, 0,  2,  "Inrush Charging     "}, //  50s inrush 
	{30,  40, 150, 1,  2,  "Compressor Starting "}, // compressor start
	{45,  60, 150, 1,  2,  "Current Burst    45s"}, // 60 sec Acceleration 
	
	{300, 50, 150, 2,  2,  "Heating Mode    300s"}, // 5min 40s heat mode
	{70,  50, 150, 1,  2,  "Heating Test  60 sec"}, // 1min heat mode Judge
	
	{10,  0,  10,  1,  2,  "Stop Compressor 10s "}, // 10sec  - stop compressor 
	{100, 60, 10,  1,  1,  " EEV Test      100s "}, // 120sec  - switch to cool - EEV Gas pumping
	
	{200, 60, 200, 3,  1,  "Cooling Mode    200s"}, // 2min max freq Eev -med	
	{60,  60, 200, 3,  1,  "Cooling Test  60 sec"}, // 1min max freq eev-med  //strong judje
	
	{60,  60, 50,  3,  1,  "Perform Pump Down   "},  // perform pump down
	{10,  30, 50,  3,  1,  "Disconnect Power    "}, // stop condition  --  or end condition 
	{0,   0,   0,  0,  0,  "Test Ended			"}
	};
const struct SequenceType DCI_HITACHI_5HP[]={
//  { lenght of stage in secs , compfreq, eev, fan speed, RV,message }
	{5,   0,  150, 0,  2,  "Power connected     "},  // test started
	{55,  0,  150, 0,  2,  "Inrush Charging     "}, //  50s inrush 
	{30,  40, 150, 1,  2,  "Compressor Starting "}, // compressor start
	{45,  60, 150, 1,  2,  "Current Burst    45s"}, // 60 sec Acceleration 
	
	{300, 60, 150, 1,  2,  "Heating Mode    300s"}, // 5min 40s heat mode
	{70,  60, 150, 1,  2,  "Heating Test  60 sec"}, // 1min heat mode Judge
	
	{10,  0,  10,  1,  2,  "Stop Compressor 10s "}, // 10sec  - stop compressor 
	{100, 70, 10,  1,  1,  " EEV Test      100s "}, // 120sec  - switch to cool - EEV Gas pumping
	
	{200, 70, 200, 3,  1,  "Cooling Mode    200s"}, // 2min max freq Eev -med	
	{60,  70, 200, 3,  1,  "Cooling Test  60 sec"}, // 1min max freq eev-med  //strong judje
	
	{60,  70, 50,  3,  1,  "Perform Pump Down   "},  // perform pump down
	{10,  30, 50,  3,  1,  "Disconnect Power    "},  // stop condition  --  or end condition 
	{0,   0,   0,  0,  0,  "Test Ended			"}
	};
	

const struct SequenceType DCI_HITACHI_4HP[]={
//  { lenght of stage in secs , compfreq, eev, fan speed, RV,message }
	{5,   0,  150, 0,  2,  "Power connected     "},  // test started
	{55,  0,  150, 0,  2,  "Inrush Charging     "}, //  50s inrush 
	{30,  40, 150, 1,  2,  "Compressor Starting "}, // compressor start
	{45,  60, 150, 1,  2,  "Current Burst    45s"}, // 60 sec Acceleration 
	{300, 55, 150, 1,  2,  "Heating Mode    300s"}, // 5min 40s heat mode
	{70,  55, 150, 1,  2,  "Heating Test  60 sec"}, // 1min heat mode Judge
	
	{10,  0,  10,  1,  2,  "Stop Compressor 10s "}, // 10sec  - stop compressor 
	{100, 70, 10,  1,  1,  " EEV Test      100s "}, // 120sec  - switch to cool - EEV Gas pumping
	
	{200, 70, 200, 3,  1,  "Cooling Mode    200s"}, // 2min max freq Eev -med	
	{60,  70, 200, 3,  1,  "Cooling Test  60 sec"}, // 1min max freq eev-med  //strong judje
	
	{60,  70, 50,  3,  1,  "Perform Pump Down   "},  // perform pump down
	{10,  30, 50,  3,  1,  "Disconnect Power    "},  // stop condition  --  or end condition 
	{0,   0,   0,  0,  0,  "Test Ended			"}
	};



const struct SequenceType DCI_ELECTRA_4HP[]={
//  { lenght of stage in secs , compfreq, eev, fan speed, RV,message }
	{5,   0,  100, 0,  2,  "Power connected     "},  // test started
	{55,  0,  100, 0,  2,  "Inrush Charging     "}, //  50s inrush 
	{30,  40, 100, 3,  2,  "Compressor Starting "}, // compressor start
	{45,  65, 150, 3,  2,  "Current Burst    45s"}, // 60 sec Acceleration 
	{300, 55, 150, 3,  2,  "Heating Mode    300s"}, // 5min 40s heat mode
	{70,  55, 150, 3,  2,  "Heating Test  60 sec"}, // 1min heat mode Judge
	
	{10,  0,  10,  3,  2,  "Stop Compressor 10s "}, // 10sec  - stop compressor 
	{100, 70, 10,  3,  1,  " EEV Test      100s "}, // 120sec  - switch to cool - EEV Gas pumping
	
	{200, 60, 150, 3,  1,  "Cooling Mode    200s"}, // 2min max freq Eev -med	
	{60,  60, 150, 3,  1,  "Cooling Test  60 sec"}, // 1min max freq eev-med  //strong judje
	
	{60,  70, 50,  3,  1,  "Perform Pump Down   "},  // perform pump down
	{10,  30, 50,  3,  1,  "Disconnect Power    "},  // stop condition  --  or end condition 
	{0,   0,   0,  0,  0,  "Test Ended			"}
	};


void StartSequenceJob (void)
{	
	flag_sequence_running=1;
};
//int DoSequenceJob(const struct SequenceType *p_sequence, unsigned char *mssg )
int DoSequenceJob(const struct SequenceType *p_sequence, struct PresetType *preset, const unsigned char** p_mssg )
{  //	const struct SequenceType Data;
	static bank3 unsigned char curent_stage;
	unsigned int dsj_temp=0;
	unsigned int lenght=0;
	unsigned int index=0;
	if (flag_sequence_running)
	{
		dsj_temp =getSec();
		lenght=p_sequence[curent_stage].lenght;
		if (dsj_temp >lenght)
		{	resetTime();
			
			curent_stage+=1;
			GIE=0; // disable interrupt
			setMainWindow();
			GIE=1; // enable again - its made for prevention stack overflow
			preset->EEV_value = p_sequence[curent_stage].EEV_value;
			preset->Compressor_freq = p_sequence[curent_stage].Compressor_freq;
			preset->Fan_speed = p_sequence[curent_stage].Fan_speed; 
			preset->Mode = p_sequence[curent_stage].Mode;
			asm("nop");

			if (p_sequence[curent_stage].lenght==0)
			{
				lenght= 600;
				flag_sequence_running=0;
			};
		};
		*p_mssg=p_sequence[curent_stage].Message;
		return lenght-dsj_temp;
	} 
	else return 0;
};


void SequenceStop(void)
{ 	
	flag_sequence_running=0;
	myPreset.Compressor_freq=0;
	myPreset.EEV_value=300;
	myPreset.Fan_speed=0;
	myPreset.Mode=0;
};

int GetSequenceDuration(const struct SequenceType *p_sequence)
{	unsigned char i=0;

	static int duration;
	duration=0;
 	while (p_sequence[i].lenght !=0)
	{
		duration+=p_sequence[i++].lenght;
	}	
	return duration;
};

